﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Mono.Cecil;
using OpenReflect.Common;
using OpenReflect.Domain.Contracts.Declarations;
using OpenReflect.Services.Builders;

//using System.Data.lin

namespace OpenReflect.Test.BuilderTests
{
	/// <summary>
	///This is a test class for MethodDeclarationBuilderTest and is intended
	///to contain all MethodDeclarationBuilderTest Unit Tests
	///</summary>
	[TestClass]
	public class MethodDeclarationBuilderTest
	{
		private AssemblyDefinition Definition { get; set; }

		/// <summary>
		///Gets or sets the test context which provides
		///information about and functionality for the current test run.
		///</summary>
		public TestContext TestContext { get; set; }

		#region Additional test attributes

		// 
		//You can use the following additional attributes as you write your tests:
		//
		//Use ClassInitialize to run code before running the first test in the class
		//[ClassInitialize()]
		//public static void MyClassInitialize(TestContext testContext)
		//{
		//}
		//
		//Use ClassCleanup to run code after all tests in a class have run
		//[ClassCleanup()]
		//public static void MyClassCleanup()
		//{
		//}
		//
		//Use TestInitialize to run code before running each test
		[TestInitialize]
		public void MyTestInitialize()
		{
			Definition =
				AssemblyFactory.GetAssembly("OpenReflect.Test.TestBinaries.dll");
			//@"C:\Users\sidarok\Desktop\ReflectWithCecil\OpenReflect.Test.TestBinaries\bin\Debug\OpenReflect.Test.TestBinaries.dll");
		}

		//
		//Use TestCleanup to run code after each test has run
		//[TestCleanup()]
		//public void MyTestCleanup()
		//{
		//}
		//

		#endregion

		/// <summary>
		///A test for CreateMethodDeclaration
		///</summary>
		[TestMethod]
		public void should_method_names_match()
		{
			IMethodDeclarationBuilder target = new MethodDeclarationBuilder(); // TODO: Initialize to an appropriate value
			TypeDefinition aDef = Definition.MainModule.Types["OpenReflect.Test.TestBinaries.TestClass1"];
			MethodDefinition cecilDef = TestHelper.CreateMethodDefinition(aDef, "AnAbstractMethod");
			IMethodDeclaration actual = target.CreateMethodDeclaration(cecilDef);
			Assert.AreEqual(cecilDef.Name, actual.Name);
		}

		/// <summary>
		///A test for CreateMethodDeclaration
		///</summary>
		[TestMethod]
		public void should_method_be_abstract()
		{
			IMethodDeclarationBuilder target = new MethodDeclarationBuilder(); // TODO: Initialize to an appropriate value
			TypeDefinition aDef = Definition.MainModule.Types["OpenReflect.Test.TestBinaries.TestClass1"];
			MethodDefinition cecilDef = TestHelper.CreateMethodDefinition(aDef, "AnAbstractMethod");
			IMethodDeclaration actual = target.CreateMethodDeclaration(cecilDef);
			Assert.AreEqual(cecilDef.IsAbstract, actual.IsAbstract);
		}

		/// <summary>
		///A test for CreateMethodDeclaration
		///</summary>
		[TestMethod]
		public void should_method_be_public()
		{
			IMethodDeclarationBuilder target = new MethodDeclarationBuilder(); // TODO: Initialize to an appropriate value
			TypeDefinition aDef = Definition.MainModule.Types["OpenReflect.Test.TestBinaries.TestClass1"];
			MethodDefinition cecilDef = TestHelper.CreateMethodDefinition(aDef, "AnAbstractMethod");
			IMethodDeclaration actual = target.CreateMethodDeclaration(cecilDef);
			Assert.AreEqual(Accessor.Public, actual.AccessModifier);
		}


		/// <summary>
		///A test for CreateMethodDeclaration
		///</summary>
		[TestMethod]
		public void should_method_be_static()
		{
			IMethodDeclarationBuilder target = new MethodDeclarationBuilder(); // TODO: Initialize to an appropriate value
			TypeDefinition aDef = Definition.MainModule.Types["OpenReflect.Test.TestBinaries.TestClass1"];
			MethodDefinition cecilDef = TestHelper.CreateMethodDefinition(aDef, "AStaticMethod");
			IMethodDeclaration actual = target.CreateMethodDeclaration(cecilDef);
			Assert.AreEqual(true, actual.IsStatic);
		}

		/// <summary>
		///A test for CreateMethodDeclaration
		///</summary>
		[TestMethod]
		public void should_method_not_be_static()
		{
			IMethodDeclarationBuilder target = new MethodDeclarationBuilder(); // TODO: Initialize to an appropriate value
			TypeDefinition aDef = Definition.MainModule.Types["OpenReflect.Test.TestBinaries.TestClass1"];
			MethodDefinition cecilDef = TestHelper.CreateMethodDefinition(aDef, "NormalAddMethod");
			IMethodDeclaration actual = target.CreateMethodDeclaration(cecilDef);
			Assert.AreEqual(false, actual.IsStatic);
		}


		/// <summary>
		///A test for CreateMethodDeclaration
		///</summary>
		[TestMethod]
		public void should_method_be_virtual()
		{
			IMethodDeclarationBuilder target = new MethodDeclarationBuilder(); // TODO: Initialize to an appropriate value
			TypeDefinition aDef = Definition.MainModule.Types["OpenReflect.Test.TestBinaries.TestClass1"];
			MethodDefinition cecilDef = TestHelper.CreateMethodDefinition(aDef, "VirtualAddMethod");
			IMethodDeclaration actual = target.CreateMethodDeclaration(cecilDef);
			Assert.AreEqual(true, actual.IsVirtual);
		}
	}
}